<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        *{
            padding: 0;
            margin: 0;
            list-style: none;
        }
        li{
            padding: 10px;
            margin: 10px;
            border: 1px solid red;
        }
    </style>
</head>

<body>
    <!-- 定义挂载点 -->
    <div id="app">
        <!-- 1.渲染数据 -->
        <ul>
            <li v-for="item in news" :key="item.id">
                <p>新闻标题：{{item.title}}</p>
                <p>感染人数：{{item.con}}</p>
                <p>发布时间：{{item.time|filterTime}}</p>
            </li>
        </ul>
    </div>

    <script>
        //全局-定义在所有实例的前面
        Vue.filter("filterTime",(time)=>{
            let oDate = new Date(time*1); //通过时间戳，创建时间对象
            let y = oDate.getFullYear();
            let m = (oDate.getMonth() + 1 + "").padStart(2,"0");
            let d = (oDate.getDate()+"").padStart(2,"0");
            let h = (oDate.getHours()+"").padStart(2,"0");
            let mi = (oDate.getMinutes()+"").padStart(2,"0");
            let s = (oDate.getSeconds()+"").padStart(2,"0");
            return y+'-'+m+'-'+d + " " + h+":"+mi+":"+s
        })
        new Vue({
            //挂载点
            el: "#app",
            //数据
            data: {
                //后端 -- 时间二次处理
                news: [{
                    id: 1,
                    title: "北京新增病例",
                    con: "1例",
                    time: "1685331945000"
                }, {
                    id: 2,
                    title: "陕西新增病例",
                    con: "5例",
                    time: "1685339145000"
                }, {
                    id: 3,
                    title: "甘肃新增病例",
                    con: "2例",
                    time: "1685418345000"
                },]
            },
            //方法
            methods: {}
        })
    </script>
</body>

</html>